import jsYaml, { Type } from "js-yaml";

export type YAMLPlanetResourcesMap = Record<number, YAMLPlanetResources>;

export type YAMLPlanetResources = {
  // 能量
  power: number;

  // 劳动力
  workforce: number;

  // 周期时长，以分钟为单位
  cycle_minutes: number;

  // 收获仓库的最大容量
  harvest_silo_max: number;

  // 成熟周期时长，以分钟为单位
  maturation_cycle_minutes: number;

  // 成熟百分比
  maturation_percent: number;

  // 成熟仓库的最大容量
  mature_silo_max: number;

  // 试剂收获数量
  reagent_harvest_amount: number;

  // 试剂类型ID
  reagent_type_id: number;
};

export const YAMLPlanetResourcesSchema = jsYaml.DEFAULT_SCHEMA.extend([
  new Type("!YAMLPlanetResourcesMap", {
    kind: "mapping",
    construct: (data: YAMLPlanetResources) => {
      data.power = Number(data.power);
      data.workforce = Number(data.workforce);
      data.cycle_minutes = Number(data.cycle_minutes);
      data.harvest_silo_max = Number(data.harvest_silo_max);
      data.maturation_cycle_minutes = Number(data.maturation_cycle_minutes);
      data.maturation_percent = Number(data.maturation_percent);
      data.mature_silo_max = Number(data.mature_silo_max);
      data.reagent_harvest_amount = Number(data.reagent_harvest_amount);
      data.reagent_type_id = Number(data.reagent_type_id);
      return data;
    },
    instanceOf: Object,
    represent: (data: any) => data,
  }),
]);
